#ifndef WEATHERFORECAST_H
#define WEATHERFORECAST_H

#include "slidemenu.h"
#include "dataparse.h"
#include "dataformat.h"
#include "systemtray.h"
#include "complexInterface.h"
#include "dayinfoInterface.h"
#include "tempdrawInterface.h"
#include "multidatasInterface.h"

#include <QWidget>
#include <QPainter>
#include <QPropertyAnimation>

QT_BEGIN_NAMESPACE
namespace Ui {
class WeatherForecast;
}
QT_END_NAMESPACE

class WeatherForecast : public QWidget
{
    Q_OBJECT

public:
    WeatherForecast(QWidget *parent = nullptr);
    ~WeatherForecast();
    void initDatasList();
    // 加载插件
    void loadPlugins();
    // 更新天气UI
    void updateWeatherUI();
    void clearLayout(QLayout* layout);
    void resizeEvent(QResizeEvent*) override;
    void paintEvent(QPaintEvent* event) override;
    void closeEvent(QCloseEvent *event) override;

private:
    Ui::WeatherForecast *ui;

    // 默认天气城市
    QString defaultCity = "Shenzhen";

    // 托盘处理类
    SystemTray * trayHandler;

    // 天气数据获取类
    DataParse * dataParse;
    // 天气数据存储类
    QVector<FutureDays> m_Future;
    CurrentDay m_Current;
    bool hasCurrent = false;
    bool hasFuture = false;

    // 插件类
    MultiDatasInterface * m_Datas = nullptr;
    TempDrawInterface    * m_Draw = nullptr;
    DayInfoInterface     * m_Info = nullptr;
    ComplexInterface  * m_Complex = nullptr;

    // 城市列表
    SlideMenu* m_menu;  // 城市列表菜单
    QPropertyAnimation m_menuAnimation; // 菜单动画
    bool m_menuExpanded = false; // 菜单展开状态

    // 背景图片加载
    QPixmap m_cachedBg;
    QSize m_lastSize;

public slots:
    // 错误处理
    void onError(const QString& error);

    // 数据处理
    void handleFutureData(const QVector<FutureDays> &futuredays);
    void handleCurrentData(const CurrentDay &currentday);

    // 城市列表
    void toggleMenu(bool show);
    void handleCitySelect(const QString &city);

    // 按键刷新
    void flushedInfo();

protected:
    bool eventFilter(QObject *watched, QEvent *event) override;
};
#endif // WEATHERFORECAST_H
